package com.appspot.yourvirtualgymtrainer;

import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

public class UserSOP {
	  public static Entity updateUser(String login, String password, String email) {
		  Entity user = getUser(login);
		  if(user == null){
			  user = new Entity("User",login);
			  user.setProperty("login", login);
			  user.setProperty("password", password);
			  user.setProperty("email", email);
		  } else {
			  user.setProperty("login", login);
			  user.setProperty("password", password);
			  user.setProperty("email", email);
		  } 
		  Util.persistEntity(user);
		  return user;
	  }
	  
	  /**
	   * Get product entity
	   * @param name : name of the product
	   * @return: product entity
	   */
	  public static Entity getUser(String name) {
	  	Key key = KeyFactory.createKey("User",name);
	  	return Util.findEntity(key);
	  }

}
